package org.emet.jee.console.dao.security;

import org.emet.dao.NonEmptyValueHashMap;
import org.emet.jee.console.entity.security.Authority;
import org.emet.jee.core.dao.Page;
import org.emet.jee.core.dao.hibernate.HibernateDao;
import org.emet.service.dto.AuthorityCriteria;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 * 授权对象的泛型DAO.
 */
@Repository
public class AuthorityDao extends HibernateDao<Authority, Long> {
	public Page<Authority> search(Page<Authority> page, AuthorityCriteria criteria) {
		Criteria c = getSession().createCriteria(Authority.class);
		NonEmptyValueHashMap<String, Object> propertyNameValues = new NonEmptyValueHashMap<String, Object>();
		propertyNameValues.put("name", criteria.getName());
		propertyNameValues.put("displayName", criteria.getDisplayName());
		c.add(Restrictions.allEq(propertyNameValues));
		page.setOrderBy("id");
		page.setOrder("desc");
		return findPage(page, c);
	}
}
